namespace RIS.TMP.WEB.APP.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class AllContext : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.CFGroupPM",
                c => new
                    {
                        GPMId = c.Int(nullable: false, identity: true),
                        GPMName = c.String(nullable: false),
                        Remarks = c.String(),
                        RecordStatus = c.String(),
                        CreateBy = c.String(),
                        CreateWhen = c.DateTime(),
                        UpdateBy = c.String(),
                        UpdateWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.GPMId);
            
            CreateTable(
                "dbo.CFEmployee",
                c => new
                    {
                        EmId = c.Int(nullable: false, identity: true),
                        EmCode = c.String(),
                        FirstName_Th = c.String(nullable: false),
                        FirstName_Eg = c.String(nullable: false),
                        SurName_Th = c.String(nullable: false),
                        SurName_Eg = c.String(nullable: false),
                        Telephone = c.String(),
                        DsId = c.Int(nullable: false),
                        GenderId = c.Int(nullable: false),
                        BrId = c.Int(nullable: false),
                        GPMId = c.Int(nullable: false),
                        Remarks = c.String(),
                        RecordStatus = c.String(),
                        CreateBy = c.String(),
                        CreateWhen = c.DateTime(),
                        UpdateBy = c.String(),
                        UpdateWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.EmId)
                .ForeignKey("dbo.CDivision", t => t.DsId, cascadeDelete: true)
                .ForeignKey("dbo.CFBranch", t => t.BrId, cascadeDelete: true)
                .ForeignKey("dbo.CFGroupPM", t => t.GPMId, cascadeDelete: true)
                .Index(t => t.DsId)
                .Index(t => t.BrId)
                .Index(t => t.GPMId);
            
            CreateTable(
                "dbo.CDivision",
                c => new
                    {
                        DsId = c.Int(nullable: false, identity: true),
                        DsName = c.String(nullable: false),
                        Remarks = c.String(),
                        RecordStatus = c.String(),
                        CreateBy = c.String(),
                        CreateWhen = c.DateTime(),
                        UpdateBy = c.String(),
                        UpdateWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.DsId);
            
            CreateTable(
                "dbo.CFBranch",
                c => new
                    {
                        BrId = c.Int(nullable: false, identity: true),
                        BrName = c.String(nullable: false),
                        Remarks = c.String(),
                        RecordStatus = c.String(),
                        CreateBy = c.String(),
                        CreateWhen = c.DateTime(),
                        UpdateBy = c.String(),
                        UpdateWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.BrId);
            
            CreateTable(
                "dbo.UserLogin",
                c => new
                    {
                        IdLogin = c.Int(nullable: false, identity: true),
                        User = c.String(nullable: false),
                        Password = c.String(nullable: false),
                        EmId = c.Int(nullable: false),
                        RecordStatus = c.String(),
                        CreateBy = c.String(),
                        CreateWhen = c.DateTime(),
                        UpdateBy = c.String(),
                        UpdateWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.IdLogin)
                .ForeignKey("dbo.CFEmployee", t => t.EmId, cascadeDelete: true)
                .Index(t => t.EmId);
            
            CreateTable(
                "dbo.CAddCar",
                c => new
                    {
                        AddCarId = c.Int(nullable: false, identity: true),
                        AddCarUnit = c.Int(),
                        AddCarNo = c.String(),
                        AddCarlicence = c.String(),
                        AddCarRegDate = c.DateTime(),
                        CarNoProperty = c.String(),
                        CarBrand = c.String(),
                        CarModel = c.Int(),
                        CarType = c.Int(),
                        MachineNo = c.String(),
                        ChassisNo = c.String(),
                        CarPistons = c.String(),
                        CarPower = c.String(),
                        WheelAxle = c.String(),
                        FreightWeight = c.String(),
                        CarWeight = c.String(),
                        RoueSize = c.Int(),
                        CarProject = c.String(),
                        StartCon = c.DateTime(),
                        EndCon = c.DateTime(),
                        AddCarYear = c.String(),
                        AddCarStatus = c.Int(),
                        Pic = c.String(),
                        Remarks = c.String(),
                        ExireContract = c.DateTime(),
                        RecordStatus = c.String(),
                        CreateBy = c.String(),
                        CreateWhen = c.DateTime(),
                        UpdateBy = c.String(),
                        UpdateWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.AddCarId)
                .ForeignKey("dbo.CModelCar", t => t.CarModel)
                .ForeignKey("dbo.CRoueSize", t => t.RoueSize)
                .ForeignKey("dbo.CStatusRepair", t => t.AddCarStatus)
                .ForeignKey("dbo.CStageCar", t => t.CarType)
                .ForeignKey("dbo.CFBranch", t => t.AddCarUnit)
                .Index(t => t.CarModel)
                .Index(t => t.RoueSize)
                .Index(t => t.AddCarStatus)
                .Index(t => t.CarType)
                .Index(t => t.AddCarUnit);
            
            CreateTable(
                "dbo.CModelCar",
                c => new
                    {
                        ModelCarId = c.Int(nullable: false, identity: true),
                        ModelCarName = c.String(),
                        Remarks = c.String(),
                        RecordStatus = c.String(),
                        CreateBy = c.String(),
                        CreateWhen = c.DateTime(),
                        UpdateBy = c.String(),
                        UpdateWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.ModelCarId);
            
            CreateTable(
                "dbo.CRoueSize",
                c => new
                    {
                        RoueSizeId = c.Int(nullable: false, identity: true),
                        RoueSize = c.String(),
                        Remarks = c.String(),
                        RecordStatus = c.String(),
                        CreateBy = c.String(),
                        CreateWhen = c.DateTime(),
                        UpdateBy = c.String(),
                        UpdateWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.RoueSizeId);
            
            CreateTable(
                "dbo.CStatusRepair",
                c => new
                    {
                        StatusReId = c.Int(nullable: false, identity: true),
                        StatusReName = c.String(),
                        Remarks = c.String(),
                        RecordStatus = c.String(),
                        CreateBy = c.String(),
                        CreateWhen = c.DateTime(),
                        UpdateBy = c.String(),
                        UpdateWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.StatusReId);
            
            CreateTable(
                "dbo.CStageCar",
                c => new
                    {
                        StageCarId = c.Int(nullable: false, identity: true),
                        StageCarName = c.String(),
                        Remarks = c.String(),
                        RecordStatus = c.String(),
                        CreateBy = c.String(),
                        CreateWhen = c.DateTime(),
                        UpdateBy = c.String(),
                        UpdateWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.StageCarId);
            
            CreateTable(
                "dbo.CCategoryRepair",
                c => new
                    {
                        CReId = c.Int(nullable: false, identity: true),
                        CReName = c.String(),
                        Remarks = c.String(),
                        RecordStatus = c.String(),
                        CreateBy = c.String(),
                        CreateWhen = c.DateTime(),
                        UpdateBy = c.String(),
                        UpdateWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.CReId);
            
            CreateTable(
                "dbo.CCheckPlan",
                c => new
                    {
                        ChpId = c.Int(nullable: false, identity: true),
                        ChpName = c.String(),
                        Remarks = c.String(),
                        RecordStatus = c.String(),
                        CreateBy = c.String(),
                        CreateWhen = c.DateTime(),
                        UpdateBy = c.String(),
                        UpdateWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.ChpId);
            
            CreateTable(
                "dbo.COutsource",
                c => new
                    {
                        OutId = c.Int(nullable: false, identity: true),
                        OutName = c.String(),
                        OutAddress = c.String(),
                        Remarks = c.String(),
                        RecordStatus = c.String(),
                        CreateBy = c.String(),
                        CreateWhen = c.DateTime(),
                        UpdateBy = c.String(),
                        UpdateWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.OutId);
            
            CreateTable(
                "dbo.CProjectContact",
                c => new
                    {
                        ProConId = c.Int(nullable: false, identity: true),
                        ProConName = c.String(),
                        Remarks = c.String(),
                        RecordStatus = c.String(),
                        CreateBy = c.String(),
                        CreateWhen = c.DateTime(),
                        UpdateBy = c.String(),
                        UpdateWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.ProConId);
            
            CreateTable(
                "dbo.MRestoreToRepair",
                c => new
                    {
                        ReId = c.Int(nullable: false, identity: true),
                        BrId = c.Int(nullable: false),
                        ReCode = c.String(),
                        RefCode = c.String(),
                        ReJobsiteNo = c.Int(nullable: false),
                        ResId = c.Int(nullable: false),
                        CReId = c.Int(nullable: false),
                        ChpId = c.Int(nullable: false),
                        AdminNo = c.Int(nullable: false),
                        OutId = c.Int(nullable: false),
                        Firstdate = c.DateTime(nullable: false),
                        Lastdate = c.DateTime(nullable: false),
                        StatusReId = c.Int(nullable: false),
                        BuyNo = c.String(),
                        StatusClose = c.Int(nullable: false),
                        Remarks = c.String(),
                        RecordStatus = c.String(),
                        CreateBy = c.String(),
                        CreateWhen = c.DateTime(nullable: false),
                        UpdateBy = c.String(),
                        UpdateWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.ReId);
            
            CreateTable(
                "dbo.MRestoreToAdmin",
                c => new
                    {
                        ResId = c.Int(nullable: false, identity: true),
                        AddCarId = c.Int(nullable: false),
                        StatusRes = c.Int(nullable: false),
                        ResDate = c.DateTime(nullable: false),
                        SentToDatePair = c.DateTime(),
                        ResCode = c.String(nullable: false),
                        MileNo = c.Int(),
                        CReId = c.Int(nullable: false),
                        Facstatus = c.Int(nullable: false),
                        MRestore = c.Int(nullable: false),
                        ApproveNo = c.Int(nullable: false),
                        Remarks = c.String(),
                        RecordStatus = c.String(),
                        CreateBy = c.String(),
                        CreateWhen = c.DateTime(nullable: false),
                        UpdateBy = c.String(),
                        UpdateWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.ResId)
                .ForeignKey("dbo.CAddCar", t => t.AddCarId, cascadeDelete: true)
                .ForeignKey("dbo.CCategoryRepair", t => t.CReId, cascadeDelete: true)
                .Index(t => t.AddCarId)
                .Index(t => t.CReId);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.MRestoreToAdmin", new[] { "CReId" });
            DropIndex("dbo.MRestoreToAdmin", new[] { "AddCarId" });
            DropIndex("dbo.CAddCar", new[] { "AddCarUnit" });
            DropIndex("dbo.CAddCar", new[] { "CarType" });
            DropIndex("dbo.CAddCar", new[] { "AddCarStatus" });
            DropIndex("dbo.CAddCar", new[] { "RoueSize" });
            DropIndex("dbo.CAddCar", new[] { "CarModel" });
            DropIndex("dbo.UserLogin", new[] { "EmId" });
            DropIndex("dbo.CFEmployee", new[] { "GPMId" });
            DropIndex("dbo.CFEmployee", new[] { "BrId" });
            DropIndex("dbo.CFEmployee", new[] { "DsId" });
            DropForeignKey("dbo.MRestoreToAdmin", "CReId", "dbo.CCategoryRepair");
            DropForeignKey("dbo.MRestoreToAdmin", "AddCarId", "dbo.CAddCar");
            DropForeignKey("dbo.CAddCar", "AddCarUnit", "dbo.CFBranch");
            DropForeignKey("dbo.CAddCar", "CarType", "dbo.CStageCar");
            DropForeignKey("dbo.CAddCar", "AddCarStatus", "dbo.CStatusRepair");
            DropForeignKey("dbo.CAddCar", "RoueSize", "dbo.CRoueSize");
            DropForeignKey("dbo.CAddCar", "CarModel", "dbo.CModelCar");
            DropForeignKey("dbo.UserLogin", "EmId", "dbo.CFEmployee");
            DropForeignKey("dbo.CFEmployee", "GPMId", "dbo.CFGroupPM");
            DropForeignKey("dbo.CFEmployee", "BrId", "dbo.CFBranch");
            DropForeignKey("dbo.CFEmployee", "DsId", "dbo.CDivision");
            DropTable("dbo.MRestoreToAdmin");
            DropTable("dbo.MRestoreToRepair");
            DropTable("dbo.CProjectContact");
            DropTable("dbo.COutsource");
            DropTable("dbo.CCheckPlan");
            DropTable("dbo.CCategoryRepair");
            DropTable("dbo.CStageCar");
            DropTable("dbo.CStatusRepair");
            DropTable("dbo.CRoueSize");
            DropTable("dbo.CModelCar");
            DropTable("dbo.CAddCar");
            DropTable("dbo.UserLogin");
            DropTable("dbo.CFBranch");
            DropTable("dbo.CDivision");
            DropTable("dbo.CFEmployee");
            DropTable("dbo.CFGroupPM");
        }
    }
}
